#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QTimerEvent>
#include <QTimer>


#ifndef Q_MOC_RUN
#include <ros/ros.h>
#include <std_msgs/String.h>
#include <sensor_msgs/Imu.h>
#include <sensor_msgs/PointCloud2.h>
#include <geometry_msgs/TwistStamped.h>
#endif
#include "cc_window.h"
namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    void rosClose();

public Q_SLOTS:
    void on_button_connect_clicked();  //push connect
    void on_button_up_clicked();  //push up
    void on_button_down_clicked();  //push down
    void on_button_left_clicked();  //push left
    void on_button_right_clicked();  //push right
    void on_button_reset_clicked();  //push reset
    void onStateChanged(int state);

private:
    Ui::MainWindow *ui;

    //ros sub
    ros::Subscriber imu_subscriber_;
    ros::Subscriber lidar_subscriber_;
    ros::Subscriber cur_twist_sub_;

    //ros pub
    ros::Publisher control_pub_;
    ros::Publisher control_mode_pub_;

    QTimer *update_time_;
    CCWindow *m_point_cloud_viewer_ = nullptr;

    float m_set_vel_;
    float m_set_angle_;

    bool ros_flag_ = false;

    int id1_;
    void timerEvent(QTimerEvent *event);

    //ros
    bool rosInit(const std::string &master_url, const std::string &host_url);
    void imuCallback(const sensor_msgs::Imu::ConstPtr &msg);
    void lidarCallback(const sensor_msgs::PointCloud2::ConstPtr &msg);
    void callbackNavTwistRaw(const geometry_msgs::TwistStampedConstPtr &msg);

    void setControlMode(int mode);
    void setControlData(const float vel, const float angle, bool flag = false);
    void reset_twist();

    void initUI();

private slots:
    void time_update();
    
};

#endif // MAINWINDOW_H
